<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "https://github.com/rbatis/rbatis_sql/raw/main/mybatis-3-mapper.dtd">
<mapper>
    <sql id="select_self">
        (id,
        user_name,
        age,
        phone,
        create_time,
        password,
        org_id,
        company_id,
        state,
        del_flag)
    </sql>
    <insert id="insert_batch">
        insert into user
        <include refid="select_self"></include>
        <foreach collection="array" index="key" item="item" open="(" close=")" separator=",">
            values #{item}
        </foreach>
    </insert>
    <select id="select_by_condition">
        select * from user
        <where>
            <if test="user_name != ''">
                and name like concat('%',#{name},'%')
            </if>
            <if test="org_id != ''">
                and org_id = #{org_id}
            </if>
            <if test="company_id != ''">
                and company_id =#{company_id}
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="get_role_by_user">
        select a.* from role a left join user_role b on a.role_id = b.role_id where user_id = #{user_id}
    </select>
</mapper>